﻿/*
 
Celerity: Sensory Overload
Copright 2012 by Adam Hill, David Gannon, Thomas Tamblyn & Patrick Ytting
Contact: adam.hill@outlook.com
Website: adamhill.org
Licence: MS-Pl Licence
  
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Celerity.World.Particles
{
	public class EmitterFactory
	{
		private List<ExplosionEmitter> explosionEmitters;
		private ParticleFactory particleFactory;

		public EmitterFactory(ParticleFactory particleFactory)
		{
			this.particleFactory = particleFactory;
			explosionEmitters = new List<ExplosionEmitter>();
		}

		public void CreateExplosionEmitter(Vector3 position, Color colour, GameTime gameTime)
		{
			float duration = 0.25f;
			float particlesPerSecond = 1000.0f;
			int accentProbability = 10;
			float velocityMagMax = 150.0f;
			float velocityMagMin = 100.0f;
			ExplosionEmitter em = new ExplosionEmitter(position, colour, duration, particlesPerSecond, accentProbability, velocityMagMax, velocityMagMin, gameTime, particleFactory);
			explosionEmitters.Add(em);
		}

		public void CullEmitters()
		{
			//TODO: add code for other emitters here
			for (int i = 0; i < explosionEmitters.Count; i++)
			{
				if (!explosionEmitters[i].isAlive) explosionEmitters.RemoveAt(i);
			}
		}

		public void Update(GameTime gameTime)
		{
			//TODO: add code for other emitters here
			foreach (ExplosionEmitter em in explosionEmitters)
				em.Update(gameTime);


			CullEmitters(); // keep this at the end
		}

	}
}
